package com.sample.systemui.view;

import android.graphics.PixelFormat;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.AdapterView;

import com.sample.systemui.R;
import com.sample.servicefragment.DummyServiceFragment;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class NavigationBar extends DummyServiceFragment {

    private List<HashMap<String, Object>> dataSourceList = new ArrayList<HashMap<String, Object>>();

    @Override
    public View onCreateView(LayoutInflater inflater) {
        View view = inflater.inflate(R.layout.navigation_bar, null, false);

        /**
         * sample9 支持拖动的gridviewdemo  step5: find view并且为之指定Apdapter，实现item的添加。
         */
        final DragGridView mDragGridView = (DragGridView) view.findViewById(R.id.dragGridView);

        for (int i = 0; i < 15; i++) {
            HashMap<String, Object> itemHashMap = new HashMap<String, Object>();
            itemHashMap.put("item_image",R.drawable.ic_launcher);
            itemHashMap.put("item_text", "拖拽 " + Integer.toString(i));
            dataSourceList.add(itemHashMap);
        }
        final DragAdapter mDragAdapter = new DragAdapter(getContext(), dataSourceList);

        mDragGridView.setAdapter(mDragAdapter);

        mDragGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                // 这演示了点击一个item时，会移除这个item。
                mDragGridView.removeItemAnimation(position);
            }
        });

        return view;
    }

    @Override
    public WindowManager.LayoutParams createLayoutParams() {

        WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(
                /* width */
                WindowManager.LayoutParams.MATCH_PARENT,
                /* height */
                (int)getContext().getResources().getDimension(R.dimen.panel_window_height),
                /* type */
                WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY, // temp for debug.
//                WindowManager.LayoutParams.TYPE_INPUT_METHOD.TYPE_NAVIGATION_BAR,
                /* flag */
                /**
                 * sample7:允许软键盘弹出
                 * 不要设置如下flag：FLAG_ALT_FOCUSABLE_IM/FLAG_NOT_FOCUSABLE/FLAG_LOCAL_FOCUS_MODE
                 */
                WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
                        | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
                /* format */
                PixelFormat.RGBA_8888
        );
        layoutParams.gravity =  Gravity.TOP;
        layoutParams.setTitle("NavigationBar");
        layoutParams.packageName = getContext().getPackageName();
        return layoutParams;
    }
}
